package config

import (
	"flag"
	"github.com/BurntSushi/toml"
	"github.com/sirupsen/logrus"
	"strings"
	"time"
)

var Config Conf

type Conf struct {
	Host     string
	Duration time.Duration
	Level    string
	Watchers []string
	Server   Server
	Redis    Redis
}

type Server struct {
	Url string
}

type Redis struct {
	Host string
	Port int
	Auth string
}

func init() {
	var (
		watchers   string
		log        string
		duration   int
		configPath string
	)
	flag.StringVar(&watchers, "watcher", "cpu", "watchers")
	flag.StringVar(&log, "log", "debug", "日志级别")
	flag.IntVar(&duration, "d", 10, "监控间隔时间")
	flag.StringVar(&configPath, "config", "./client.toml", "配置文件")
	flag.Parse()
	_, err := toml.DecodeFile(configPath, &Config)
	if err != nil {
		logrus.Errorf("配置文件解析失败：%v", err)
	}

	Config.Duration = time.Second * time.Duration(duration)
	Config.Level = log
	Config.Watchers = strings.Split(watchers, ",")
	logrus.Printf("当前配置信息：%+v", Config)
}
